package com.cc8w.service;

import org.springframework.stereotype.Service;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * 解析InetAddres类
 * InetAddress:静态类操作
 */
@Service
public class InetAddressService {

    InetAddress inetAddress = InetAddress.getLocalHost();

    public InetAddressService() throws UnknownHostException {
    }

    //获得主机名
    public String getHostName(){
        return inetAddress.getHostName();
    }

    //获得主机名
    public String getHostAddress(){
        return inetAddress.getHostAddress();
    }
    //获得字节地址(获得字节有可能有负数)
    public byte[] getBtyeAddress(){
        byte[] b = inetAddress.getAddress();
        return b;
    }
    /**
     * Description: 负数byte转正int
    */
   public static Integer byteToInteger(Byte b) {
       return 0xff & b;
   }
    
    
    
    

    //根据IP地址获得主机名
    public void getNameByIp() throws UnknownHostException {
        //InetAddress.getByName("127.0.0.1");
        InetAddress inetAddress2 = InetAddress.getByName("EH04XC8SXW23WJ5");
        System.out.println("计算机名:"+inetAddress2.getHostName());
        System.out.println("ip地址:"+inetAddress2.getHostAddress());

    }





}
